package cn.gjxblog.aop.proxy.spring.demo2;


import cn.gjxblog.aop.proxy.spring.demo1.MyAfterReturningAdvice;
import cn.gjxblog.aop.proxy.spring.demo1.UserService;
import cn.gjxblog.aop.proxy.spring.demo1.UserServiceImpl;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;

public class ProxyFactoryBeanConfig {


    @Bean
    public UserService userService(){
        return new UserServiceImpl();
    }

    @Bean
    public MyAfterReturningAdvice afterReturningAdvice(){
        return new MyAfterReturningAdvice();
    }

    @Bean
    public ProxyFactoryBean proxyFactoryBean(UserService userService){
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        proxyFactoryBean.setTarget(userService);
        proxyFactoryBean.setInterceptorNames("afterReturningAdvice");

        return proxyFactoryBean;
    }
}
